/**
 * 
 */
package com.bolbachchan.blog.validator.common;

import org.springframework.stereotype.Component;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

/**
 * @author Chaitanya
 * 
 */
@Component
public class LoginValidator implements Validator {

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.springframework.validation.Validator#supports(java.lang.Class)
	 */
	@Override
	public boolean supports(Class<?> clazz) {
		return clazz.isAssignableFrom(LoginValidator.class);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.springframework.validation.Validator#validate(java.lang.Object,
	 * org.springframework.validation.Errors)
	 */
	@Override
	public void validate(Object target, Errors errors) {
		// LoginFormObj form = (LoginFormObj) target;
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "username",
				"Username is blank, but required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password",
				"Password is blank, but required");
	}

}
